package com.myres.reg.db;


import com.myres.db.ConnectionPool;
import com.myres.model.Category;

import java.util.List;
import java.util.ArrayList;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import com.myres.model.Product;
import com.myres.model.User;
import com.myres.util.UIDTool;
public class RegService {
	
	public int insertUser(User user) {
		Connection con=null;
		try{
		con=ConnectionPool.getPool().getConnection();
		PreparedStatement pstmt=con.prepareStatement("insert into res_users(_no,_name,_password,_email,_mobile,_address,_gender,_age,_career,_score,_rank,_role) values(" +
				"?,?,?,?,?,?,?,?,?,?,?,?)");
		pstmt.setString(1,user.getNO());
		pstmt.setString(2, user.getName());
		pstmt.setString(3,user.getPassword());
		pstmt.setString(4, user.getEmail());
		pstmt.setString(5, user.getMobile());
		pstmt.setString(6, user.getAddress());
		pstmt.setByte(7, user.getGender());
		pstmt.setInt(8, user.getAge());
		pstmt.setString(9, user.getCareer());
		pstmt.setInt(10,user.getScore());
		pstmt.setInt(11,user.getRank());
		pstmt.setInt(12, user.getRole());
		
		int result =pstmt.executeUpdate();
		con.close();
		return result;
	}catch(SQLException e){
		e.printStackTrace();
		return -1;
	}finally{
		try{
		con.close();
		}catch(Exception e){
			
		}
	}
	}

}
